<template>
    <div class="layout" :class="{'layout-hide-text': spanLeft < 5}">
        <Row type="flex">
            <i-col :span="spanLeft" class="layout-menu-left">
                <Menu :mode="modeType" theme="dark" width="auto" :active-name="this.$route.path" @on-select="menuSelect"
                      accordion>
                    <div class="layout-logo-left">
                        <img src="../common/img/user.png">
                        <div class="userinfo">
                            <Dropdown placement="bottom-end">
                        <span class="head-img">
                            <!--{{curUserName}}-->

							<p class="user_name">{{curUserName}}<Icon class="ionic_down" type="chevron-down"></Icon></p>
                        </span>
                                <Dropdown-menu slot="list">
                                    <Dropdown-item>修改密码</Dropdown-item>
                                    <Dropdown-item @click.native="logout()" divided>退出</Dropdown-item>
                                </Dropdown-menu>
                            </Dropdown>
                        </div>
                    </div>
                    <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden">
                        <Submenu :name="item.name" v-if="!item.leaf">
                            <template slot="title">
                                <Icon :type="item.iconCls" :size="iconSize"></Icon>
                                <span class="layout-text">{{item.name}}</span>
                            </template>
                            <template v-for="(child,childIndex) in item.children" v-if="!child.hidden">
                                <Menu-item :name="child.path">{{child.name}}</Menu-item>
                            </template>
                        </Submenu>
                        <template v-if="item.leaf&&item.children.length>0">
                            <Menu-item :name="item.children[0].path">
                                <Icon :type="item.iconCls" :size="iconSize"></Icon>
                                <span class="layout-text">{{item.children[0].name}}</span>
                            </Menu-item>
                        </template>
                    </template>
                </Menu>
            </i-col>
            <i-col :span="spanRight">
                <div class="layout-header">
                    <i-button type="text" @click="toggleClick">
                        <Icon type="navicon" size="32"></Icon>
                    </i-button>

                </div>
                <div class="layout-breadcrumb">
                    <Breadcrumb>
                        <Breadcrumb-item href="#">应用中心</Breadcrumb-item>
                        <Breadcrumb-item>{{$route.name}}</Breadcrumb-item>
                    </Breadcrumb>
                </div>
                <div class="layout-content">
                    <div class="layout-content-main">
                        <router-view></router-view>
                    </div>
                </div>
                <div class="layout-copy">
                    <span>© 2016 Copyright.</span>
                </div>
            </i-col>
        </Row>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                spanLeft: 5,
                spanRight: 19,
                modeType: "vertical",
                logoIsDisplay: false,
                curUserName: 'admin'
            }
        },
        computed: {
            iconSize () {
                return this.spanLeft === 5 ? 20 : 24;
            }
        },
        methods: {
            toggleClick () {
                if (this.spanLeft === 5) {
                    this.spanLeft = 2;
                    this.spanRight = 22;
                } else {
                    this.spanLeft = 5;
                    this.spanRight = 19;
                }
            },
            menuSelect(name) {
                this.$router.push({path: name});
            },
            logout() {
                this.$router.push('/login');
            }
        }
    }
</script>
<style scoped>
    .layout {
        background: #f5f7f9;
        position: absolute;
        overflow: hidden;
        height: 100%;
        width: 100%;
    }

    .layout-breadcrumb {
        padding: 10px 15px 0;
    }

    .layout-content {
        min-height: 200px;
        margin: 15px;
        overflow: hidden;
        background: #fff;
        border-radius: 4px;
    }

    .layout-content-main {
        padding: 10px;
    }

    .layout-copy {
        text-align: center;
        padding: 10px 0 20px;
        color: #9ea7b4;
    }

    .ivu-row-flex {
        height: 100%;
    }

    .layout-menu-left {
        background: #464c5b;
    }

    .layout-header {
        height: 60px;
        background: #fff;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
    }

    .layout-logo-left {
        width: 90%;
        height: 30px;
        background: #5b6270;
        border-radius: 3px;
        margin: 15px auto;
    }

    .layout-ceiling-main a {
        color: #9ba7b5;
    }

    .layout-hide-text .layout-text {
        display: none;
    }

    .ivu-col {
        transition: width .2s ease-in-out;
    }

    .ivu-col-span-5 {
        width: 13.833333%;
    }

    .ivu-col-span-19 {
        width: 86.16666667%;
    }

    .layout-logo-left[data-v-324c4303] {
        width: 90%;
        height: 100%;
        background: none;
        border-radius: 3px;
        padding-top: 35px;
        text-align: center;
    }

    .layout-copy {
        /* text-align: center; */
        border-top: 1px solid #dee5e7;
        padding: 0 20px;
        position: fixed;
        bottom: 0;
        width: 100%;
        text-align: left;
    }

    .user_name {
        z-index: 100;
        color: #fff;
        font-size: 20px;
        font-weight: bold;
        margin-top: 10px;
    }

    .ionic_down {
        font-size: 14px;
        margin-left: 10px;
        color: #7793a7;
    }
    .ivu-menu-dark {
        background: #56566E;
    }
    .layout-menu-left{
        background: #56566E;
    }
    .ivu-menu-dark.ivu-menu-vertical .ivu-menu-item-active:not(.ivu-menu-submenu), .ivu-menu-dark.ivu-menu-vertical .ivu-menu-submenu-title-active:not(.ivu-menu-submenu) {
        color: #fff;
    }
    .ivu-menu-dark.ivu-menu-vertical .ivu-menu-item, .ivu-menu-dark.ivu-menu-vertical .ivu-menu-submenu-title {
        color: #fff;
    }
    .ivu-menu-dark.ivu-menu-vertical .ivu-menu-item, .ivu-menu-dark.ivu-menu-vertical .ivu-menu-submenu-title {
        color: #fff !important;
    }
    .ivu-menu-dark.ivu-menu-vertical .ivu-menu-submenu .ivu-menu-item-active, .ivu-menu-dark.ivu-menu-vertical .ivu-menu-submenu .ivu-menu-item-active:hover {
        background: #F96F39!important;
    }
</style>